import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/me/data/repository/me_repository.dart';
import 'package:casdon/modules/me/data/repository/me_repository_impl.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class SocialBindUsecase {
  final MeRepository _repository;

  const SocialBindUsecase(this._repository);

  Future<bool> execute({
    required String source,
    required String authCode,
  }) async {
    try {
      await _repository.postSocialBind(source: source, code: authCode);
      return true;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("SocialBindUsecase 失败", e.toString(), StackTrace.current);
      return false;
    }
  }
}

final socialBindUsecaseProvider = Provider(
  (ref) => SocialBindUsecase(ref.read(meRepositoryProvider)),
);
